                                                                                                                                  pg_get_functiondef                                                                                                                                   
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 CREATE OR REPLACE FUNCTION public.handle_check_in(p_member_id uuid, p_name text, p_email text, p_class_type text, p_check_in_date date, p_card_id uuid DEFAULT NULL::uuid, p_trainer_id uuid DEFAULT NULL::uuid, p_is_1v2 boolean DEFAULT false, p_time_slot text DEFAULT NULL::text)+
  RETURNS jsonb                                                                                                                                                                                                                                                                       +
  LANGUAGE plpgsql                                                                                                                                                                                                                                                                    +
 AS $function$                                                                                                                                                                                                                                                                        +
 DECLARE                                                                                                                                                                                                                                                                              +
   v_check_in_id uuid;                                                                                                                                                                                                                                                                +
   v_is_extra boolean := false;                                                                                                                                                                                                                                                       +
   v_is_private boolean := (p_class_type = 'private');                                                                                                                                                                                                                                +
   v_card_id uuid := p_card_id;                                                                                                                                                                                                                                                       +
   v_message text;                                                                                                                                                                                                                                                                    +
   v_duplicate_check boolean;                                                                                                                                                                                                                                                         +
 BEGIN                                                                                                                                                                                                                                                                                +
   -- 检查是否重复签到，使用新的布尔值函数                                                                                                                                                                                                                                            +
   v_duplicate_check := check_duplicate_check_in_bool(p_member_id, p_check_in_date, p_class_type, p_time_slot);                                                                                                                                                                       +
                                                                                                                                                                                                                                                                                      +
   IF v_duplicate_check THEN                                                                                                                                                                                                                                                          +
     RETURN jsonb_build_object(                                                                                                                                                                                                                                                       +
       'success', false,                                                                                                                                                                                                                                                              +
       'message', '今天已经在这个时段签到过了',                                                                                                                                                                                                                                       +
       'isDuplicate', true                                                                                                                                                                                                                                                            +
     );                                                                                                                                                                                                                                                                               +
   END IF;                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                      +
   -- 其余代码保持不变...                                                                                                                                                                                                                                                             +
                                                                                                                                                                                                                                                                                      +
   RETURN jsonb_build_object(                                                                                                                                                                                                                                                         +
     'success', true,                                                                                                                                                                                                                                                                 +
     'message', '签到成功',                                                                                                                                                                                                                                                           +
     'isExtra', v_is_extra,                                                                                                                                                                                                                                                           +
     'checkInId', v_check_in_id                                                                                                                                                                                                                                                       +
   );                                                                                                                                                                                                                                                                                 +
                                                                                                                                                                                                                                                                                      +
 EXCEPTION                                                                                                                                                                                                                                                                            +
   WHEN OTHERS THEN                                                                                                                                                                                                                                                                   +
     RETURN jsonb_build_object(                                                                                                                                                                                                                                                       +
       'success', false,                                                                                                                                                                                                                                                              +
       'message', SQLERRM,                                                                                                                                                                                                                                                            +
       'error', SQLERRM                                                                                                                                                                                                                                                               +
     );                                                                                                                                                                                                                                                                               +
 END;                                                                                                                                                                                                                                                                                 +
 $function$                                                                                                                                                                                                                                                                           +
 
(1 row)

